
//团队详情
Auth()
var teamId	 = globalFun.GetQueryString('teamId');
if(is_team==1){
	$("#join_one").css('display','block');
}else if(is_team==2){
	$("#join_one").css('display','none');
}
	$.ajax({
		type:"post",
		url:apicom+"/team/teamDetail",
		async:true,
		data:{
			teamId:	teamId
		},
		success:function(res){
			console.log(res)
			if(res.code==200){
				var content = res.data.teamDetail;
				var list = res.data.activityList
				$('h3').html(content.teamName);
				$('.status').html(content.status)
				$('.span1').html('成立日期:'+content.createTime);
				$('.img1').attr('src',content.imgUrl);
				$('.address').html(content.areaName);
				$('.type').html(content.address);
				$('.people').html(content.teamNum);
				$('.zm_time').html(content.memberNum);
				$('.fb_time').html(content.createdTime);			
				$('#team_d').html(content.description);
				$('.c_people').html(content.linkName);
				$('.c_phone').html('手机:'+content.telPhone);
				$('.c_mail').html('邮箱:'+content.email);
				var ss = ''
				for(i = 0; i<list.length; i++){
					ss+='<tr><td>'+list[i].title+'</td><td>'+list[i].beginTime+'</td><td>'+list[i].status+'</td></tr>'
				}
				$('tbody').html(ss)
				
			}
		},
		error:function(){
			
		}
	});
	$('.team_d').on('click',function(){
		$(this).addClass('t_type');
		$(this).siblings().removeClass('t_type');
		$('#team_d').show();
		$('#c_active').hide();	
		$('.liuyan').hide();	
	})
	$('.c_active').on('click',function(){
		$(this).addClass('t_type');
		$(this).siblings().removeClass('t_type');
		$('#team_d').hide();
		$('#c_active').show();	
		$('.liuyan').hide();
	})
	$('.c_liuyan').on('click',function(){
		$(this).addClass('t_type');
		$(this).siblings().removeClass('t_type');
		$('#team_d').hide();
		$('#c_active').hide();	
		$('.liuyan').show();	
	})
//加入团队
$('#join_one').on('click',function(){
	if(localStorage.getItem('user_info')){
		var joinObj = {
			teamId:teamId,
			uuid:uuid,
			loginId:id,
			loginType:is_team,
			type:1
		}
		$.ajax({
			type:"post",
			url:apicom+"/apply/joinTeam",
			async:true,
			data:joinObj,
			success:function(res){
				if(res.code==200){
					$('.mengban').css('display','block');
					$('.tips').text(res.message)
				}else if(res.code==0){
					$('.mengban').css('display','block');
					$('.tips').text(res.message)
				}
				
			},
			error:function(err){
				console.log(err)
			}
		});

	}else{
		window.location.href = 'login.html'
	}

})
//关闭按钮
$('.btn_close').on('click',function(){
	$('.mengban').css('display','none');
})
$('.close_s').on('click',function(){
	$('.mengban').css('display','none');
})
//渲染评论列表
massge()

function massge() {
	$.ajax({
		type: "post",
		url: apicom + "/activity/commentList",
		async: true,
		data: {
			id: teamId,
			type: 2
		},
		success: function(res) {
			var content = res.data;
			liuyan(content);
		},
		error: function() {

		}
	});
}

function liuyan(pList) {
	var ss = ''
	for(var i = 0; i < pList.length; i++) {
		ss += '<div class="list_one">'
		ss += '<div class="list_top">'
		ss += '<img src="' + pList[i].imgUrl + '"/>'
		ss += '<dl class="hf_dl">'
		ss += '<dt>' + pList[i].name + '</dt>'
		ss += '<dd class="hf_info">' + pList[i].content + '</dd>'
		if(pList[i].commentReplyVOList.length == 0) {
			ss += '<dd class="hf_bottom"><span>' + pList[i].createTime + '</span><span data-name="' + pList[i].name + '" data-id="' + pList[i].id + '" class="huifu">回复</span></dd></dl></div>'
			ss += '</div></div>'
		} else {
			ss += '<dd class="hf_bottom"><span>' + pList[i].createTime + '</span><span data-name="' + pList[i].name + '" data-id="' + pList[i].id + '" class="huifu">回复</span></dd></dl></div><div class="list_bottom">'
			for(var j = 0; j < pList[i].commentReplyVOList.length; j++) {

				ss += '<div class="list_two">'
				ss += '<p class="two_left"><span class="hf_one">' + pList[i].commentReplyVOList[j].name + '</span>回复<span class="hf_two">' + pList[i].commentReplyVOList[j].replyName + '</span>:</p>'
				ss += '<dl class="two_right">'
				ss += '<dt>' + pList[i].commentReplyVOList[j].replyContent + '</dt>'
				ss += '<dd class="hf_bottom1"><span data-name="' + pList[i].commentReplyVOList[j].name + '" data-id="' + pList[i].id + '" class="huifu">回复</span><span>' + pList[i].commentReplyVOList[j].createTime + '</span></dd></dl></div>'

			}
		}

		ss += '</div></div>'

	}
	$('.liuyan_list').html(ss)

}
//发表留言
$('#btn_fb').on('click', function() {
	var liuyan = $('#liuyan').val();
	if(localStorage.getItem('user_info')) {
		var lyObj = {
			commentId: teamId,
			uuid: uuid,
			username: name,
			loginId: id,
			loginType: is_team,
			content: liuyan,
			commentType: 2
		}
		$.ajax({
			type: "post",
			url: apicom + "/comment/addComment",
			async: true,
			data: lyObj,
			success: function(res) {
				if(res.code == 200) {
					$('.mengban').css('display', 'block');
					$('.tips').html('发布成功')
					massge();
				} else if(res.code == 0) {
					$('.mengban').css('display', 'block');
					$('.tips').html(res.message)
				}

			},
			error: function(err) {
				conosle.log(err)
			}
		});

	} else {
		$('.mengban').css('display', 'block');
		$('.tips').html('请先登录后再进行评论')
	}
})
//回复留言
var reaName;
var oneId;//首次回复
$('.message').on('click','.huifu',function() {
	if(localStorage.getItem('user_info')) {
		oneId = $(this).attr('data-id')
		reaName = $(this).attr('data-name')
		$('.mengban1').css('display', 'block');
	} else {
		$('.mengban').css('display', 'block');
		$('.tips').html('请先登录后再进行评论')
	}
})
$('.btn_hf').on('click',function() {
	var liuyan = $('#description').val();
		var hfObj = {
			commentId: oneId,
			uuid: uuid,
			username: name,
			loginId: id,
			loginType: is_team,
			content: liuyan,
			replyName:reaName
		}
		$.ajax({
			type: "post",
			url: apicom + "/comment/replyComment",
			async: true,
			data: hfObj,
			success: function(res) {
				if(res.code == 200) {
					$('.mengban1').css('display', 'none');
					$('.mengban').css('display', 'block');
					$('.tips').html('回复成功')
					massge();
				} else if(res.code == 0) {
					$('.mengban1').css('display', 'block');
					$('.mengban').css('display', 'block');
					$('.tips').html(res.message)
				}

			},
			error: function(err) {
				conosle.log(err)
			}
		});

})